<template>
  <div class="residentBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <h3>门店列表</h3>
      </div>
      <div class="text item">
        <span>门店</span>
        <el-input placeholder="请输入门店名" v-model="key" clearable></el-input>
        <span>服务范围</span>
      </div>
      <el-select v-model="services" multiple clearable placeholder="请选择">
        <el-option
          v-for="item in seleceList"
          :key="item.id"
          :label="item.name"
          :value="item.name"
        >
        </el-option>
      </el-select>
      <el-button type="primary" @click="Stores">查询</el-button>
    </el-card>
    <div class="btn">
      <el-button type="primary">添加</el-button>
      <el-button type="danger" @click="DelAllStores">批量删除</el-button>
    </div>
    <el-table
      border
      :data="list"
      style="width: 100%"
      :header-cell-style="{
        background: '#fafafa',
        color: '#333',
        fontWeight: '600',
        textAlign: 'center',
        fontSize: '14px',
      }"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>
      <el-table-column align="center" label="门店" width="140">
        <template slot-scope="scope">
          <el-link type="primary">{{ scope.row.name }}</el-link>
        </template>
      </el-table-column>
      <el-table-column prop="address" align="center" label="地址">
      </el-table-column>
      <el-table-column
        prop="images"
        align="center"
        label="门店logo"
        width="160"
      >
        <template slot-scope="scoped">
          <el-image
            style="width: 50px; height: 50px"
            :src="
              'http://estate.eshareedu.cn/estate/upload/' + scoped.row.images
            "
          ></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="services" align="center" label="服务范围">
      </el-table-column>
      <el-table-column prop="username" align="center" label="店主">
      </el-table-column>
      <el-table-column prop="tel" align="center" label="联系电话">
      </el-table-column>
      <el-table-column prop="startTime" align="center" label="营业时间">
        <template slot-scope="scoped">
          <span>{{ scoped.row.startTime }} ~ {{ scoped.row.endTime }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="" align="center" label="操作">
        <template v-slot:default="scoped">
          <el-button type="primary" icon="el-icon-edit" circle></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="DelStores(scoped.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
      <Pageination
      :pageSize="formInline.pageSize"
      :total="total"
      @changpage="Stores"
    />
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import http from "../api/stores";
import Pageination from "../components/common/page1.vue";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {Pageination},
  data() {
    //这里存放数据
    return {
      value: "",
      formInline: {
        page: 1,
        pageSize: 5,
      },

      key: "",
      services: "",
      total: 0,
      seleceList: "",
      list: [],
      id: [],
    };
  },
  //方法集合
  methods: {
    //   分页
    handleSizeChange(val) {
      this.pageSize = val;
      this.Stores();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.Stores();
    },
    //列表
    async Stores(params) {
      const { data } = await http.stores({params:Object.assign(this.formInline,params)
      });
      this.total = data.data.counts;
      this.list = data.data.list;
    },
    // 删除
    DelStores(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(async () => {
          const { data } = await http.Delstores({ id: id });
          console.log(data)
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.Stores();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //获取复选框的id
    handleSelectionChange(id) {
      this.id = id;
    },
    //批量删除
    DelAllStores() {
      let ids = [];
      this.id.forEach((item) => {
        ids.push(item.id);
      });
      this.$confirm("是否删除选中的数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(async () => {
          const { data } = await http.DelAllstores({ ids: ids });
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.Stores();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //搜索的下拉框  //bug
    async Storeservices() {
      const { data } = await http.storeservices();
      console.log(data);
      this.seleceList = data.list;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.Stores();
    this.Storeservices();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
};
</script>
<style lang="less" scoped>
.residentBox {
  .box-card {
    padding-bottom: 20px;
    .item {
      float: left;
      :nth-child(2) {
        width: 180px;
        margin-left: 10px;
      }
      :nth-child(3) {
        margin-left: 30px;
        margin-right: 10px;
      }
    }
    .el-select {
      float: left;
    }
    .el-button {
      margin-left: 30px;
      width: 100px;
    }
  }
  .btn {
    margin-top: 14px;
    .el-button {
      width: 100px;
    }
  }
  .el-table {
    margin-top: 16px;
    .el-table-column {
      text-align: center;
    }
  }
  .el-pagination {
    margin-top: 8px;
    margin-left: 30%;
  }
}
</style>